package com.yulang.springbootnetty.webscoket;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.stereotype.Component;

@Component
public class WServer {

    private static class SingletionWsServer{
        static final WServer instance = new WServer();
    }

    public static WServer getInstance(){
        return SingletionWsServer.instance;
    }

    private EventLoopGroup mainGroup;

    private EventLoopGroup subGroup;

    private ServerBootstrap serverBootstrap;

    private ChannelFuture  future;

    public WServer(){
        mainGroup = new NioEventLoopGroup();
        subGroup = new NioEventLoopGroup();
        serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(mainGroup,subGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new WServerInit());
    }
    public void start(){
        this.future = serverBootstrap.bind(8088);
        System.out.println("netty 启动成功");
    }

}
